import java.util.*;
public class 分割回文串 {

    List<List<String>> ans;
    List<String> path;
    int n;
    public List<List<String>> partition(String ss) {
        ans = new ArrayList<>();
        path = new ArrayList<>();
        char[] s = ss.toCharArray();
        n = s.length;
        dfs(s,0);
        return ans;
    }

    public void dfs(char[] s,int i) {
        if (i == n) {
            ans.add(new ArrayList<>(path));
        }


        for (int j = i;j < n;j++) {
            if (check(s,i,j)) {
                path.add(new String(s,i,j - i + 1));
                dfs(s,j + 1);
                path.remove(path.size() - 1);
            }
        }
    }

    public boolean check(char[] s,int left,int right) {
        while (left < right) {
            if (s[left] != s[right]) {
                return false;
            }
            left++;
            right--;
        }
        return true;
    }
}
